#include "data_es.hpp"
#include "user.hxx"
#include "logger.hpp"
#include <gflags/gflags.h>
#include <thread>

DEFINE_bool(mode, false, "运行模式： true-发布模式； false-测试模式");
DEFINE_string(file, "", "发布模式日志更新地址");
DEFINE_int32(level, 1, "默认日志等级");

DEFINE_string(host, "http://120.76.98.215:9200/", "这是ES服务器的地址");

int main(int argc, char* argv[]) {
    google::ParseCommandLineFlags(&argc, &argv, true); 
    init_logger(FLAGS_mode, FLAGS_file, FLAGS_level);
    std::shared_ptr<elasticlient::Client> _es_client = zhiang::ESClientFactory::create({FLAGS_host});
    std::shared_ptr<zhiang::ESUser> client = std::make_shared<zhiang::ESUser>(_es_client);
    client->createIndex();
    client->appendData("用户1", "名字1", "签名1", "电话1", "头像1");
    client->appendData("用户2", "名字2", "签名2", "电话2", "头像2");
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::vector<User> ret = client->search("名字", {"user1"});
    for(auto& user : ret)
    {
        std::cout << "---------------" << std::endl;
        std::cout << user.user_id() << std::endl;
        std::cout << user.phone() << std::endl;
        std::cout << user.nickname() << std::endl;
        std::cout << user.description() << std::endl;
        std::cout << user.avatar_id() << std::endl;
    }
    return 0;
}